fix(federation): register local users on Matrix when self-joining federated rooms#39427
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Proposed changes
Problem
When a local Rocket.Chat user self-joins a federated room via channels.join (or through the UI "Join" button), they are not registered on the Matrix homeserver. This means:
Root Cause
The existing beforeAddUserToRoom hook at ee/server/hooks/federation/index.ts:105-139 requires an inviter parameter:
When a user self-joins via channels.join, addUserToRoom is called without an inviter, so the federation hook silently exits and the Matrix bridge is never notified.
Users who are explicitly invited (via addUserToRoom with an inviter) work correctly because the inviter parameter is present.
Fix
Added an afterJoinRoom callback that catches the self-join case:
Note on duplicate invites
For explicitly invited users, both beforeAddUserToRoom (existing) and this new afterJoinRoom hook will fire. The Matrix protocol handles duplicate invite events idempotently (re-inviting an already-joined member is a no-op), so this should be safe. However, I'd appreciate confirmation on this behavior. An alternative approach would be to use a module-scoped flag to track whether beforeAddUserToRoom already handled the invite for this user.
Issue(s)
Fixes #38239 Builds on the failing e2e test from #38669
@ggazzo Would love your feedback on the approach, especially regarding the duplicate invite edge case for explicitly invited users.